﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RoomService.Listings
{
    public partial class Post : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private void Page_Init(Object sender, EventArgs e)
        {
            btnPost.Click += new EventHandler(this.Post_Click);
           
        }
        protected void Post_Click(Object sender, EventArgs e) 
        {
          

            RoomSvc.Data.Listing lease  = new RoomSvc.Data.Listing();
            RoomSvc.Data.ListingType Listing_Type = Service.ServiceClient.GetListingType("1");
            RoomSvc.Data.Person Pers = Global.currentUser;
            RoomSvc.Data.Address Address = new RoomSvc.Data.Address();


            Address.city = txtCity.Text;
            Address.state = txtState.Text;
            Address.zip_code = txtZipcode.Text;
            Address.street_address_1 = txtStreet1.Text;
            Address.street_address_2 = txtStreet2.Text;


            RoomSvc.Data.Utility Utility = new RoomSvc.Data.Utility();
            Utility.cable = txtCable.Text;
            Utility.internet = txtInternet.Text;
            Utility.water = txtWater.Text;
            string listing_title;
            string listing_desc;
            int listing_rate;
            int roommates;
            int smoking;
            string gender;
            int furnished;
            int square_ft;

            try
            {
                Address.city = txtCity.Text;
                Address.state = txtState.Text;
                Address.zip_code = txtZipcode.Text;
                Address.street_address_1 = txtStreet1.Text;
                Address.street_address_2 = txtStreet2.Text;
                Utility.cable = txtCable.Text;
                Utility.internet = txtInternet.Text;
                Utility.water = txtWater.Text;
               listing_title = txtTitle.Text;
                listing_desc = txtDescribe.Text;
                listing_rate = Convert.ToInt32(txtRate.Text);
                 roommates = Convert.ToInt32(txtRoommates.Text);
                 smoking = Convert.ToInt32(txtSmoking.Text); ;
                
                 furnished = Convert.ToInt32(txtFurnished.Text);
                 square_ft = Convert.ToInt32(txtSmoking.Text);
            }
            catch (Exception x) { return; }
            DateTime date_term_start = DateTime.Now;
            if (rb_male.Checked) { gender = "M"; }
            else
            {
                gender = "F";
            }
   
            
            DateTime date_term_end =  DateTime.Now;
            DateTime date_listing_expire =  DateTime.Now;

            Address.Address_Type = new RoomSvc.Data.AddressType();
            
            if (Rb_House.Checked) {
               
                Address.Address_Type.Address_Type_id = 2;
            }
            if (Rb_Dorm.Checked) {
                Address.Address_Type.Address_Type_id = 4;
            }
            if (Rb_Apartment.Checked) {
                Address.Address_Type.Address_Type_id = 1;
            }
            if (Rb_Duplex.Checked) {
                Address.Address_Type.Address_Type_id = 3;
            }        

            lease.Listing_Type = Listing_Type;
            lease.Pers = Pers;
            lease.Address = Address;
            lease.Utility = Utility;
            lease.listing_title = listing_title;
            lease.listing_desc = listing_desc;
            lease.listing_rate = listing_rate;
            lease.roommates = roommates;
            lease.smoking = smoking;
            lease.gender = gender;
            lease.furnished = furnished;
            lease.square_ft = square_ft;
            lease.date_term_start = date_term_start;
            lease.date_term_end = date_term_end;
           
            lease.Listing_Type=Listing_Type;
            lease.Pers=Pers;
            lease.Address=Address;
            lease.Utility=Utility;
            Service.ServiceClient.PostListing(lease);

           



        }
      
    }
}
    
